from langchain_community.document_loaders import CSVLoader

"""
文档：
https://python.langchain.com/api_reference/community/document_loaders/langchain_community.document_loaders.csv_loader.CSVLoader.html
"""
file_path = (
    "../resource/a.csv"
)

loader = CSVLoader(file_path=file_path, encoding="UTF-8",
                   csv_args={"delimiter": ",",
                             # "quotechar": '"', # 合并两个列"狮子,哺乳动物"
                             "fieldnames": ["Name", "Species", "Age", "Habitat"]  # 增加了一行表头
                             })
data = loader.load()

for record in data[:3]:  # 获取前2个元素
    print(record)
    print("-" * 50)
